const User = require('./db/user');
const zjxModel = require('./db/zjx');
const mongoose = require('./db/setmongoose');

async function initUsers() {
  try {
    console.log('开始初始化用户数据...');
    
    // 检查是否已存在测试用户
    const existingUser = await zjxModel.findOne({ phone: '17532302869' });
    if (existingUser) {
      console.log('测试用户已存在，跳过初始化');
      return;
    }
    
    // 创建测试用户
    const testUser = new zjxModel({
      name: '测试用户',
      phone: '17532302869',
      password: '123456',
      nickName: '测试用户',
      avatar: '/static/app/icons/120x120.png',
      createdAt: new Date(),
      updatedAt: new Date()
    });
    
    await testUser.save();
    console.log('测试用户创建成功！');
    console.log('手机号: 17532302869');
    console.log('密码: 123456');
    
  } catch (error) {
    console.error('初始化用户数据失败:', error);
  } finally {
    mongoose.connection.close();
  }
}

// 如果直接运行此脚本
if (require.main === module) {
  initUsers();
}

module.exports = initUsers;
